package com.oriental.manage.service.institution.impl;

import com.oriental.manage.core.paging.Pagination;
import com.oriental.manage.core.response.ResponseDTO;
import com.oriental.manage.dao.institution.ChannelRelationshipMapper;
import com.oriental.manage.pojo.institution.ChannelRelationship;
import com.oriental.manage.service.institution.IChannelRelationshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * Created by dongyy on 2017/5/10.
 */
@Service
public class ChannelRelationshipImpl implements IChannelRelationshipService {

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    private ChannelRelationshipMapper ChannelRelationshipMapper;

    @Override
    public void queryPage(Pagination<ChannelRelationship> pagination, ChannelRelationship ChannelRelationship) {

        List<ChannelRelationship> list = ChannelRelationshipMapper.selectAll(ChannelRelationship);

        if (list != null && list.size() > 0) {
            pagination.setRowCount(list.get(0).getRowCount());
            pagination.setList(list);
        }

    }

    @Override
    public void addChannelRelationship(ResponseDTO<String> responseDTO, ChannelRelationship ChannelRelationship) {
        ChannelRelationship.setId(UUID.randomUUID().toString());
        if(ChannelRelationshipMapper.insertSelective(ChannelRelationship)>0){
            responseDTO.setSuccess(true);
        }else {
            responseDTO.setSuccess(false);
        }
    }

    @Override
    public void updateChannelRelationship(ResponseDTO<String> responseDTO, ChannelRelationship ChannelRelationship) {
        if(ChannelRelationshipMapper.updateByPrimaryKeySelective(ChannelRelationship)>0){
            responseDTO.setSuccess(true);
        }else {
            responseDTO.setSuccess(false);
        }
    }

    @Override
    public void deleteChannelRelationship(ResponseDTO<String> responseDTO, ChannelRelationship ChannelRelationship) {
        if(ChannelRelationshipMapper.deleteByPrimaryKey(ChannelRelationship)>0){
            responseDTO.setSuccess(true);
        }else {
            responseDTO.setSuccess(false);
        }
    }

    @Override
    public int check(ChannelRelationship ChannelRelationship) {
        return ChannelRelationshipMapper.checkConfig(ChannelRelationship);
    }
}
